/*
 * Copyright 2001 Alexander Boverman and the original authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _WT_APP_TABLE_H
#define _WT_APP_TABLE_H

#include <tcl.h>
#include "WtTableCmds.h"

typedef struct WtAppTableSet
{
  Tcl_HashTable tables;
  Tcl_Mutex lock;
  unsigned long seqId;
} WtAppTableSet;

typedef struct WtAppTableT
{
  Tcl_Obj *sharedTable;
  time_t accessTime;
} WtAppTable;

void WtInitAppTableSet(WtAppTableSet *set);
Tcl_Obj *WtOpenAppTable(WtAppTableSet *set, Tcl_Obj *id,
  Tcl_Interp *interp, int *created);
int WtCloseAppTable(Tcl_Obj *tbl);
int WtDeleteAppTable(WtAppTableSet *set, Tcl_Obj *id, Tcl_Interp *interp);
WtTableCmdStatus WtAppTableCmdHelper(ClientData clientData,
  Tcl_Interp *interp, int objc, Tcl_Obj *const objv[],
  int *tclRet, int readOnly, int appendUsage);
void WtAppTableCmdUsageError(Tcl_Interp *interp, Tcl_Obj *cmd,
  int readOnly);
void WtAppTableCmdAppendUsage(Tcl_Interp *interp, Tcl_Obj *cmd,
  int readOnly);
int WtAppTableCmd(ClientData clientData, Tcl_Interp *interp,
  int objc, Tcl_Obj *const objv[]);
Tcl_Obj *WtAppTableCmdGetTarget(Tcl_Obj *id, Tcl_Interp *interp);
Tcl_Obj *WtAppTableCmdGetStorage(Tcl_Obj *id, Tcl_Obj **tbl,
  Tcl_Interp *interp);
Tcl_Obj *WtNewAppTableObj();
WtAppTable *WtAppTableRep(Tcl_Obj *obj);
void WtInitAppTableCommands(Tcl_Interp *interp);

extern WtAppTableSet wtAppTables;
extern Tcl_ObjType WtAppTableType;

#endif /* !_WT_APP_TABLE_H */
